#ifndef _PLATFORM_INTERRUPT_H
#define _PLATFORM_INTERRUPT_H

/* 处理器选择 */
#if ARCH_I386
#include <i386/interrupt.h>
#elif ARCH_AMD64
#include <amd64/interrupt.h>
#endif

#include <platform/atomic.h>

/* ----中断上半部分---- */

#define IRQF_DISABLED       0x01
#define IRQF_SHARED         0x02
#define IRQF_TIMER          0x03

#define IRQA_NR (NR_IRQS * 2)

/* irq对应的处理 */
typedef struct irq_action {
    unsigned long data;
    int (*handler)(unsigned long, unsigned long);
    unsigned long flags;
    struct irq_action *next;     // 指向下一个行动
    /* 表示设备名字 */
    char *name;
} irq_action_t;

typedef struct irq_description {
    /* 硬件控制器，用来控制中断的硬件底层操作 */
    struct hardware_intr_controller *controller;
    struct irq_action *action;
    unsigned long flags;
    atomic_t device_count;       // 记录注册的设备数量

    /* 表示irq名字 */
    char *irqname;
} irq_description_t;

int register_irq(unsigned long irq,
    int (*handler)(unsigned long, unsigned long), 
    unsigned long flags,
    char *irqname,
    char *devname,
    unsigned long data);
int unregister_irq(unsigned long irq, void *data);

int handle_irq(unsigned long irq);

void init_irq_description();

#endif  /* _PLATFORM_INTERRUPT_H */
